<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>分享免费领</title>
		<meta id="viewport" name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0" />
		<meta name="format-detection" content="telephone=no" />
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<link rel="stylesheet" type="text/css" href="css/aui.css" />
		<link rel="stylesheet" type="text/css" href="css/iconfont/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
		<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
        <script src="js/art-template.js" type="text/javascript" charset="utf-8"></script>

        <!--<script src="//s.url.cn/qqun/qun/qqweb/m/qun/confession/js/vconsole.min.js"></script>-->
		<script src="js/wxrem.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			
			body,html{
				height:auto;
				padding-bottom: 1.0rem;
			}
			
			.activity-alertView .activity-list{
				margin-top: 2.6rem;
				margin-left: 1.5rem;
			}
			
			.activity-list ul {
				overflow: hidden;
			}
			
			.activity-list ul li {
				float: left;
				height: 24rem;
				width: 16.38rem;
				margin: 1.3rem 0.96rem 1.3rem 0.6rem;
				border-radius: 0.52rem;
				box-shadow: 0 0 0.52rem 0.52rem #eff0f5;
				position: relative;
			}
		</style>
	</head>
	<body>
		<div class="activity-alertView">
			<div class="activity-list" align="center">
				<div class="activity_top" align="center">
			        <p style="font-size: 2.6rem; font-weight: bold; color: #333333;">分享免费领</p>
		            <p class="stageNum" style="font-size: 1.66rem; color: #333333; margin-top: 1.3rem;"></p>
		            <p style="font-size: 1.45rem; color: #666666; margin-left: 5.2rem; margin-right: 5.2rem;">将书分享到朋友圈，好友领取成功后即可免费听本书音频，每周更新，每期最多领取一本。</p>
		        </div>
				<ul id="activity_book" style="margin-top: 1.56rem;"></ul>
			</div>
			<script type="text/html" id="activity_Item">
				{{each data.book_list}}
				  <li>
				      <div class="activity_Item_div">
				      	<div class="activity_bookView" data-bookid="{{$value.bookid}}" data-videoauthorid="{{$value.videoauthorid}}" data-copywriter="{{$value.copywriter}}" data-bookname="{{$value.bookname}}" data-bookimg="{{$value.bookimg}}" data-bookrecommend="{{$value.bookrecommend}}">
				      		<img class="activity_bookimg" src={{"http://img.readerday.com/cover/" + $value.bookimg}} style="width: 9.17rem; height: 12rem; margin-top: 2.6rem; box-shadow: 3px 3px 3px #e6e6e6;border: 0;vertical-align: middle;"/>
					        <img src="icon/listen.png" style="width: 1.5rem; height: 1.5rem; margin-left: 7rem; margin-top: -1.8rem;"/>
					        <p style="font-size: 1.45rem;width: 9.17rem; color: #333333; margin-top: 1.5rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{$value.bookname}}</p>
					        {{if ($value.isorder == 1 || userVip.type == 1)}}
					            <div class="activity_read_btn" style="margin-top: 1.6rem; margin-left: 3.25rem; margin-right: 3.25rem; height: 3.12rem; background-color: #fbd454; color: #333333; font-weight: bold; border-radius: 0.4rem; padding-top: 0.4rem;">开始听书</div>
					        {{else if share_bookid == 1}}
					            <div class="activity_share_btn" style="margin-top: 1.6rem; margin-left: 3.25rem; margin-right: 3.25rem; height: 3.12rem; background-color: #fbd454; color: #333333; font-weight: bold; border-radius: 0.4rem; padding-top: 0.4rem;">分享</div>
					        {{else if share_bookid == $value.bookid}}
					            <div class="activity_share_btn" style="margin-top: 1.6rem; margin-left: 3.25rem; margin-right: 3.25rem; height: 3.12rem; background-color: #fbd454; color: #333333; font-weight: bold; border-radius: 0.4rem; padding-top: 0.4rem;">分享</div>
					         {{else}}
					            <div class="activity_pay_btn" style="margin-top: 1.6rem; margin-left: 3.25rem; margin-right: 3.25rem; height: 3.12rem; background-color: #fbd454; color: #333333; font-weight: bold; border-radius: 0.4rem; padding-top: 0.4rem;">购买</div>
					        {{/if}}
				      	</div>
		              </div>
				  </li>
				{{/each}}
			</script>
		</div>
	</body>
	<script type="text/javascript">
		document.writeln("<script type=\"text/javascript\" src=\"js/common.js?"+ Math.random() + "\"></scr"+"ipt>");
	</script>
	<script src="js/zepto.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/md5.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/jquery-1.11.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/aui-dialog.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/aui-toast.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/purl.js"></script>
	<script type="text/javascript">
		var stage;
		var share_bookid;
		var share_str;
		function getActivityBookList(){
			$.ajax({//页面统计
				type:"get",
				url:hostUrl + "statistics/page?type=3&channel=weixin&unionid=" + unionid,
				async:true
			});
			relink = relink;
			shareWx("分享免费领", "http://img.readerday.com/activity/book105.jpg", "将书分享到朋友圈，好友领取成功后即可免费听本书音频，每周更新，每期最多领取一本。");
			$.ajax({
				type:"get",
				url: hostUrl + "other/giveonewindow?unionid=" + unionid,
				async:true,
				success: function(data) {
					stage = "第 " + data.data.num + " 期";
					$('.stageNum').text(stage);
					data.userVip = userVip;
					if (window.localStorage) {
						share_str = localStorage.getItem('share_activity');
					}else {
						share_str = getCookie('share_activity');
					}
					if (share_str) {
						var arr = share_str.split("_");
						if (stage != arr[1]) {
							share_bookid = 1;
							if (window.localStorage) {
								localStorage.removeItem('share_activity');
							} else{
								deleteCookie('share_activity');
							}
						}else {
							share_bookid = arr[0];
						}
					}else {
						share_bookid = 1;
					}
					data.share_bookid = share_bookid;
					document.getElementById('activity_book').innerHTML = template("activity_Item", data);
					console.log(data)
				}
			});
		}
		getToken(getActivityBookList);
		
		function getCookie(Name) {
			var search = Name + "=";
			if (document.cookie.length > 0) {
				 offset = document.cookie.indexOf(search);
				 if (offset != -1) {
				 	offset += search.length 
                    end = document.cookie.indexOf(";", offset) 
                    if(end == -1) end = document.cookie.length 
                    return unescape(document.cookie.substring(offset, end)) 
				 }else {
				 	return "";
				 }
			}
		}
		
		function deleteCookie(name) {
			var expdate = new Date(); 
            expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 
            setCookie(name, "", expdate); 
		}
		
		$('#activity_book').on('click', '.activity_bookimg', function(e) {
			e.stopPropagation();
			e.cancelBubble = true;
			var parent = $(this).parents('.activity_bookView')
			var type = 0;
			if (share_bookid == parent.attr('data-bookid') || !share_str) {
				type = 1;
			}
			window.location.href = "bookDetail.html?activity_type=" + type + "&stage=" + stage + "&bookid=" + parent.attr('data-bookid') + "&videoauthorid=" + parent.attr('data-videoauthorid') + "&copywriter=" + parent.attr('data-copywriter');
		})
		
		$('#activity_book').on('click', '.activity_share_btn', function(e) {
			e.stopPropagation();
			e.cancelBubble = true;
			var parent = $(this).parents('.activity_bookView')
			window.location.href = "bookDetail.html?activity_type=1&bookid=" + parent.attr('data-bookid') + "&stage=" + stage + "&videoauthorid=" + parent.attr('data-videoauthorid') + "&copywriter=" + parent.attr('data-copywriter');
		})
		
		$('#activity_book').on('click', '.activity_read_btn', function(e) {
			e.stopPropagation();
			e.cancelBubble = true;
			var parent = $(this).parents('.activity_bookView')
			location.href = "chapter.html?bookid=" + parent.attr('data-bookid') + "&bookname="+parent.attr('data-bookname')+"&bookimg=" + parent.attr('data-bookimg')+"&videoauthorid=" + parent.attr('data-videoauthorid') + "&copywriter=" + parent.attr('data-copywriter');
		})
		
		$('#activity_book').on('click', '.activity_pay_btn', function(e) {
			e.stopPropagation();
			e.cancelBubble = true;
			var parent = $(this).parents('.activity_bookView')
			window.location.href = "bookDetail.html?bookid=" + parent.attr('data-bookid') + "&videoauthorid=" + parent.attr('data-videoauthorid') + "&copywriter=" + parent.attr('data-copywriter');
		})
		
	var isPageHide = false;
       window.addEventListener('pageshow', function () {
        if (isPageHide) {
        	  setTimeout(function(){
        	  	location.reload()
		  },500)
        }
      });
    window.addEventListener('pagehide', function () {
        isPageHide = true;
    });
		
	</script>
</html>
